

$(() => {

  
  // let url = getUrl()
  let riskControl = $('.riskControl')
  let data = {}
  // let index
  // let optIndex

  $('div.list ul').on('click', 'li', function () {
    // $(this).css('background','#f7f7f8').siblings('background','none')
    let box = $(this).parent().parent().parent()
    let index = box.index()
    let optIndex = $(this).index()
    data[`option${index+1}`] = optIndex

    if (index < riskControl.length - 1) {
      // box.css({
      //   display: 'none'
      // })
      box.addClass('rm')
      riskControl.get(index + 1).style.display = 'block'

    } else {
      $.ajax({
        url: 'http://p2p.jingyubao.com/jinr/home/saveRiskAccess',
        data,
        type: 'post',
        success(res) {
          // console.log(res)
        }
      })
    }

  })

  $('.riskControl').on('click', 'div.bottom', function () {
    let box = $(this).parent()
    let index = box.index()
    if(!index) return
    riskControl.get(index).style.display = 'none';
    riskControl.get(index-1).style.display = 'block';

    // console.log('index', index)

  })

  function getUrl() {
    var kstr, vstr;
    var url1 = location.href;
    var url = "?" + url1.split('?')[1]
    var url2 = url.split('#')[0]
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url2.indexOf("?") != -1) {
      var str = url2.substr(1);
      var strs = str.split("&");
      for (var i = 0; i < strs.length; i++) {
        var idx = strs[i].indexOf('=')
        if (idx >= 0) {
          theRequest[strs[i].split("=")[0]] = unescape(strs[i].substr(idx + 1));
        } else {

        }
      }
    }
    return theRequest;
  }
})